<?php
/**
 * @Author: king
 * @Last Modified by:   king
 * Date: 2018/6/8
 * Time: 11:28
 */
namespace App\Http\Controllers\Api\v1\Rectification;

use App\Http\Controllers\Api\v1\Astro\IndexController as Index;
use App\Http\Controllers\Api\BaseController;
use App\Models\Api\Goods;
use App\Models\Api\MessageCenter;
use App\Models\Api\Orders;
use App\Models\Api\Recode;
use App\Models\Api\Rectification as RectificationModel;
use App\Models\Api\User;
use App\Models\Api\UserMsg;
use App\Tools\Rectification;
use Cache;
use DB;
use Illuminate\Http\Request;

/**
 * @title 生时校正相关接口
 * @desc 根据用户人生大事件来校正出生时间
 * @url
 * @version 1.0
 * @readme /doc/md/rectification/base.md
 * Class Index
 */
class IndexController extends BaseController
{
    protected $restActionList = ['index', 'read', 'save', 'update', 'delete', 'start', 'use'];

    /**
     * @title 查看历史记录 加入订单id字段######
     * @method GET
     * @desc /rectifications
     * @readme /doc/md/rectification/index.md
     */
    public function index(Request $request)
    {
        // 判断订单是否超时
        check_overtime();

        if (!Request()->isMethod('get')) {
            return show(config('code.error'), '未知操作', [], 403);
        }
        // 用户id
        $uid = $request->uid;
        // 页码
        $page = $request->input('page', 1);
        // 要查询的字段
        $field = ['re.id', 're.status', 're.start_time', 're.end_time', 're.create_time', 'or.order_id', 'or.trade_type'];
        $where = ['re.uid' => $uid, 're.is_del' => config('code.nodel')];
        $order = 're.id DESC';

        try
        {
            $goods = Goods::select('id', 'name', 'or_prize', 'now_prize')->where('status', config('code.status_normal'))->find(1)->toArray();

            $data = (new RectificationModel())
                ->from('rectification as re')
                ->join('orders as or', 'or.reid', '=', 're.id', 'RIGHT')
                ->where($where)
                ->orderBy('re.id', 'DESC')
                ->paginate(10, $field, $page);
        } catch (\Exception $e) {
            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        if ($data || !empty($data)) {
            foreach ($data as $k => $d) {
             if ($d->orders['status'] == '2') {
            // 假设RectificationModel有status字段，使用update方法来更新状态
             RectificationModel::where(['id'=>$d['id'],'uid'=>$uid])->update(['status'=>5]);
             $data[$k]['status'] = 5;

            }
                $data[$k]['or_prize'] = $goods['or_prize'];

                $data[$k]['now_prize'] = $goods['now_prize'];
            }
            return show(config('code.success'), '查看成功', $data);
        } else {
            return show(config('code.success'), '您还没有校正过哦，去矫正吧~', []);
        }

    }
    /**
     * @title 查看历史  加入订单id字段######
     * @method GET
     * @desc /rectification
     * @readme /doc/md/rectification/read.md
     */
    public function read(Request $request)
    {
        if (!Request()->isMethod('get')) {
            return show(config('code.error'), '未知操作', [], 403);
        }
        // 生时校正id
        $id = $request->input('reid');
        // 用户id
        //        $uid = $request->uid;
        // 要排除的字段
        $field = ['uid', 'update_time'];

        // 订单金额信息
        $gid = 1; // 生时校正

        $goods = Goods::select('id', 'name', 'or_prize', 'now_prize')->where('status', config('code.status_normal'))->find($gid)->toArray();

        if (!$goods || empty($goods)) {
            return show(config('code.error'), '商品不存在');
        }
        try
        {
            $data = RectificationModel::where(['id' => $id])->first();
            //$data->hidden($field);
            // 事件
            $data['events'] = $data->events()->orderBy('id', 'ASC')->get();
            // 校正结果
            $data['result'] = $data->result()->get(['id', 'time', 'score', 'status']);
            $return         = 0;
            if ($data->orders) {
                $return         = $data->orders->return_time;
            if ($data->orders['status'] == '2') {
               RectificationModel::where(['id'=>$id,'uid'=>$request->uid])->update(['status'=>5]);
                $data['status'] = 5;
             }
                $data['orders'] = [
                    'order_id'     => $data->orders->order_id,
                    'trade_type'   => $data->orders->trade_type,
                    'total_amount' => $data->orders->total_amount,
                ];

            } else {
                $data['orders'] = [
                    'order_id' => '',
                    'trade_type' => 0,
                    'total_amount' => $goods['now_prize'],
                ];
            }
            // 订单信息
            //$data['orders'] = $data->orders;
            //            $data['orders'] = $data->orders()->field('')->find();
            $data['return_time'] = $return;
            $data['or_prize']    = $goods['or_prize'];
//            $data['now_prize'] = $goods['now_prize'];
            $data['now_prize'] = (string)$data->orders['total_amount'];
        } catch (\Exception $e) {
            return show(config('code.error'), $e->getMessage(), [], 500);
        }
        $data = json_decode(json_encode($data, true), true);
        unset($data['orders']['status']);
        unset($data['orders']['return_time']);

        return show(config('code.success'), '查看成功', $data);
    }
    /**
     * @title 提交生时校正
     * @method POST
     * @desc /rectification
     * @readme /doc/md/rectification/save.md
     * @return int status 0失败，无有效事件，无法继续提交 || 1成功，但是有效事件太少，影响生时校正结果 || 2成功，等待支付
     * @return float or_amount 原价 99.00
     * @return float total_amount 现价 9.90
     */
    public function save(Request $request)
    {
        if (!Request()->isMethod('post')) {
            return show(config('code.error'), '未知操作', [], 403);
        }
        // 档案id
        $rid = $request->input('rid');
        // 校正开始时间
        $start_time = $request->input('start_time');
        // 校正结束时间
        $end_time = $request->input('end_time');
        if ($start_time == $end_time) {
            return show(config('code.error'), '矫正时间不能相同', []);
        }

        if (($start_time - $end_time) > 0) {
            return show(config('code.error'), '开始时间不能大于结束时间', []);
        }

        if (($start_time - $end_time) < 7200 && 7200 == ($start_time - $end_time)) {
            return show(config('code.error'), '时间不可超过两小时', []);
        }

//        if (abs(date('h',$start_time) - date('h',$end_time)) > 2) return show(config('code.error'),'时间不可超过两小时',[]);
        // 生时校正事件json
        $events = $request->input('events');
        $ev     = json_decode($events, true);
        foreach ($ev as $k => $v) {
            if ($v['time'] > time()) {
                return show(config('code.error'), '事件时间不能大于当前时间', []);
            }

        }

        // json 转 array
        $events_array = json_decode($events, true);
        // 用户id
        $uid = $request->uid;
        // 检测传参
        if (!$uid || !$rid || !$events || empty($events_array)) {
            return show(config('code.error'), '参数错误', [], 400);
        }
        // 时间范围超出两小时 或者结束时间小于开始时间
        if (($end_time - $start_time) > 7200 || ($end_time - $start_time) < 0) {
            return show(config('code.error'), '参数错误', [], 400);
        }
        $field = ['type', 'year', 'month', 'day', 'hour', 'minute', 'timezone', 'long_deg', 'long_min', 'ew', 'lat_deg', 'lat_min', 'ns', 'is_summer'];
        // 获取该档案下的出生信息 以便进行矫正
        $recode = Recode::where(['id' => $rid, 'uid' => $uid, 'isself' => 1])->first($field);

        if ($recode === null) {
            return show(config('code.error'), '当前仅限校正自己的档案', [], 400);
        }
        // 矫正范围的中点时间
        $birth_time_mid = ($start_time + $end_time) / 2;

        // 有效事件判断
        $event_array = (new Rectification())->getValidEvents($events_array, $birth_time_mid, $recode);

        // 初始化有效事件数量
        $vaild_num = 0;
        // 有效事件++
        foreach ($event_array as $ea) {
            if ($ea['status'] == 1) {
                $vaild_num++;
            }
        }

        $gid = 1; // 生时校正

        $goods = Goods::select('id', 'name', 'or_prize', 'now_prize')->where('status', config('code.status_normal'))->find($gid)->toArray();

        if (!$goods || empty($goods)) {
            return show(config('code.error'), '商品不存在');
        }

        $ret = [
            'status'       => 0,
            'or_amount'    => ($goods['or_prize']),
            'total_amount' => ($goods['now_prize']),
            'reid'         => 0,
        ];

        // 入库  付款后 加入计算队列
        try
        {

            $insert_data = [
                'uid'        => $uid,
                'rid'        => $rid,
                'start_time' => $start_time,
                'end_time'   => $end_time,
                'create_time' => time(),
            ];

            $rectification = new RectificationModel;
            $id = $rectification->insertGetId($insert_data);
           // $id = $rectification->id;
            foreach ($event_array as $event) {
                $reidevent = [
                    'type'   => $event['type'],
                    'time'   => $event['time'],
                    'desc'   => $event['desc'],
                    'status' => $event['status'],
                    'reid'   => $id,
                ];
                // var_dump($reidevent);
                $rectification->events()->insertGetId($reidevent);

            }

        } catch (\Exception $e) {
            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        $ret['reid'] = intval($id);

        if ($vaild_num < 1) {
            return show(config('code.success'), '无有效事件，会导致校正失败，请继续添加', $ret);
        }

        if ($vaild_num < 3) {
            $ret['status'] = 1;

            return show(config('code.success'), '有效事件太少，可能导致校正不准确，要继续提交吗', $ret);
        }

        $ret['status'] = 2;

        return show(config('code.success'), '待支付', $ret);
    }
    // 逐一验证用户指定出生范围内的星盘（每分钟一张盘），看对于所有有效事件，是否有四轴点的对应推进，每有一个记录1分，每张盘记录一个总得分
    // 如果有得分则可检测半有效事件是否成立，否则不检测
    // 半有效事件成立单独标记
    /**
     * @title 更新生时校正
     * @method PUT
     * @desc /rectification
     * @readme /doc/md/rectification/update.md
     * @return int status 0失败，无有效事件，无法继续提交 || 1成功，但是有效事件太少，影响生时校正结果 || 2成功，等待支付 || 3已支付
     * @return float or_amount 原价 99.00
     * @return float total_amount 现价 9.90
     */
    public function update(Request $request)
    {
        if (!Request()->isMethod('put')) {
            return show(config('code.error'), '未知操作', [], 403);
        }
        // 主键id
        $id = $request->input('reid');
        // 档案id
        $rid = $request->input('rid');
        // 校正开始时间
        $start_time = $request->input('start_time');
        // 校正结束时间
        $end_time = $request->input('end_time');
        // 生时校正事件json
        $events = $request->input('events');
        // 检测传参 主键 || 档案id || 事件json字符串
        if (!$id || !$rid || !$events) {
            return show(config('code.error'), '参数错误1', [], 400);
        }
        // 时间范围超出两小时 或者结束时间小于开始时间
        if (($end_time - $start_time) > 7200 || ($end_time - $start_time) < 0) {
            return show(config('code.error'), '参数错误2', [], 400);
        }
        if ($start_time == $end_time) return show(config('code.error'),'矫正时间不能相同',[]);
        if ( ($start_time - $end_time) > 0) return show(config('code.error'),'开始时间不能大于结束时间',[]);
        if (($start_time - $end_time) < 7200 &&  7200 ==($start_time - $end_time)) return show(config('code.error'),'时间不可超过两小时',[]);

        $ev = json_decode($events,true);
        foreach ($ev as $k=>$v)
        {
            if ($v['time'] > time()) return show(config('code.error'),'事件时间不能大于当前时间',[]);
        }

        // 获取用户id
        $uid = $request->uid;

        $field = ['type', 'year', 'month', 'day', 'hour', 'minute', 'timezone', 'long_deg', 'long_min', 'ew', 'lat_deg', 'lat_min', 'ns', 'is_summer'];
        // 获取该档案下的出生信息 以便进行矫正
        $recode = Recode::where(['id' => $rid, 'uid' => $uid, 'isself' => 1])->first($field);

        if ($recode === null) {
            return show(config('code.error'), '当前仅限校正自己的档案', [], 400);
        }
        // 矫正范围的中点时间
        $birth_time_mid = ($start_time + $end_time) / 2;
        // 所有的事件
        $events_array = json_decode($events, true);

        $event_array = (new Rectification())->getValidEvents($events_array, $birth_time_mid, $recode);

        // 初始化有效事件数量
        $vaild_num = 0;

        foreach ($event_array as $ea) {
            if ($ea['status'] == 1) {
                $vaild_num++;
            }
        }

        $gid = 1; // 生时校正

        $goods = Goods::select('id', 'name', 'or_prize', 'now_prize')->where('status', config('code.status_normal'))->find($gid)->toArray();

        if (!$goods || empty($goods)) {
            return show(config('code.error'), '商品不存在');
        }

        $ret = [
            'status'       => 0,
            'or_amount'    => ($goods['or_prize']),
            'total_amount' => ($goods['now_prize']),
            'reid'         => 0,
        ];

        $order_status = 0; // 默认未支付

        // 入库  付款后 加入计算队列
        try
        {
            $update_data = [
                'rid'        => $rid,
                'start_time' => $start_time,
                'end_time'   => $end_time,
               'update_time' => time(),
            ];

            $rectification = RectificationModel::where(['id' => $id])->first();
            // 存入生时校正表
            $rectification->update($update_data);
            // 删除生时校正事件表
            $rectification->events()->delete();

            // 存入生时校正事件表
            foreach ($event_array as $event) {
                $reidevent = [
                    'type'   => $event['type'],
                    'time'   => $event['time'],
                    'desc'   => $event['desc'],
                    'status' => $event['status'],
                    'reid'   => $id,
                ];

                $rectification->events()->insertGetId($reidevent);
            }
            //更新生时校正状态
            RectificationModel::where(['id' => $id])->update(['status' => 0]);
            // 判断支付状态
            if ($rectification->orders && $rectification->orders['status']) {
                // 已支付
                $order_status = 1;
            }
        } catch (\Exception $e) {
            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        $ret['reid']         = intval($id);
        $ret['order_status'] = $order_status;

        if ($vaild_num < 1) {
            return show(config('code.success'), '无有效事件，会导致校正失败，请继续添加', $ret);
        }

        if ($vaild_num < 3) {
            $ret['status'] = 1;

            return show(config('code.success'), '有效事件太少，可能导致校正不准确，要继续提交吗', $ret);
        }

        $ret['status'] = 2;

        return show(config('code.success'), '更新成功', $ret);
    }
    /**
     * @title 删除
     * @method DELETE
     * @readme /doc/md/rectification/delete.md
     */
    public function delete(Request $request)
    {
        if (!Request()->isMethod('delete')) {
            return show(config('code.error'), '未知操作', '', 403);
        }
        $uid = $request->uid;

        $reid = $request->input('reid');

        $rid = $request->input('rid');

        if (!$uid || !$reid || !$rid) {
            return show(config('code.error'), '参数错误', '', 400);
        }

        $rectification = RectificationModel::where(['id'=>$reid])->first()->toArray();

        if (!$rectification || $rectification['rid'] != $rid || $rectification['uid'] != $uid) {
            return show(config('code.error'), '非法操作', '', 401);
        }
        // 进行软删除
        //        $rectification->delete();
        try
        {
            RectificationModel::where(['id'=>$reid])->update(['is_del' => config('code.del')]);
        } catch (\Exception $e) {
            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        return show(config('code.success'), '删除成功', []);
    }

    /**
     * @title 开始生时校正
     * @method POST
     * @desc /start_rectification
     * @readme /doc/md/rectification/start.md
     * @return array
     */
    public function start(Request $request)
    {
        if (!Request()->isMethod('post')) {
            return show(config('code.error'), '未知操作', '', 403);
        }
        // 检测是否支付了
        $reid = $request->input('reid'); // 生时校正id

        if (!$reid) {
            return show(config('code.error'), '参数错误');
        }

        try
        {
            $rectification = RectificationModel::where(['id' => $reid])->first();
            $event_array   = $rectification->events()->get()->toArray();
            $recode        = Recode::where(['id' => $rectification['rid']])->first()->toArray();

            //$rectification->save(['status' => 1]); // 更新校正状态 1 等待校正
            RectificationModel::where(['id'=>$reid])->update(['status' => 1]);
            if ($rectification->orders && $rectification->orders->status) {
                $data = [
                	'oid' => $rectification->id,
                    'order_id' => $rectification->order_id,
                    'reid'       => $reid,
                    'start_time' => $rectification['start_time'],
                    'end_time'   => $rectification['end_time'],
                    'events'     => $event_array,
                    'recode'     => $recode,
                ];
                $queueConfig = config('queue');
                queuePush($queueConfig['rectification_task'], $data, $queueConfig['rectification_queue'],$queueConfig['rectification_delay']);

            }
        } catch (\Exception $e) {
            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        return show(config('code.success'), '开始校正，等待校正结果');
    }

    /**
     * @title 生时校正采纳
     * @method POST
     * @desc /use_rectification
     * @readme /doc/md/rectification/use.md
     * @return array
     */
    function use (Request $request) {
        if (!Request()->isMethod('post')) {
            return show(config('code.error'), '未知操作', '', 403);
        }
        $uid = $request->uid;

        $id   = $request->input('id'); // 采纳的结果id
        $reid = $request->input('reid'); // 生时校正id

        if (!$uid || !$id || !$reid) {
            return show(config('code.error'), '参数错误');
        }

        try
        {
            $rectification           = RectificationModel::where(['id' => $reid])->first();
            $rectification['result'] = $rectification->result()->where(['id' => $id])->first();
            $long_deg                = $rectification->recode->long_deg;
            $long_min                = $rectification->recode->long_min;
            $ew                      = $rectification->recode->ew;
            $lat_deg                 = $rectification->recode->lat_deg;
            $lat_min                 = $rectification->recode->lat_min;
            $ns                      = $rectification->recode->ns;
            $timezone                = $rectification->recode->timezone;
            $rid                     = $rectification->recode->id;

        } catch (\Exception $e) {

            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        $use_time  = $rectification['result']['time']; // 采纳的时间
        $year      = date('Y', $use_time);
        $month     = date('m', $use_time);
        $day       = date('d', $use_time);
        $hour      = date('H', $use_time);
        $minute    = date('i', $use_time);
        $is_summer = isSummerTime($hour, $minute, 0, $month, $day, $year) ? 1 : 0; // 是否为夏令时时间

        $Astro     = new Index();
        $longitude = ($long_deg + $long_min / 60) * $ew;
        $latitude  = ($lat_deg + $lat_min / 60) * $ns;
        // 查询当前星盘日月水金火木土等星落座落宫存入数据库
        $astro_data = $Astro->getTheRecodeAstro($year, $month, $day, $hour, $minute, $longitude, $latitude, $timezone);

        try
        {
            // 先将已采用的还原为未采用
            $rectification->result()->where('status', 1)->update(['status' => 0]);
            $rectification->result()->where('id', $id)->update(['status' => 1]);

            (new Recode())->where(['id' => $rid])->update([
                'year'      => $year,
                'month'     => $month,
                'day'       => $day,
                'hour'      => $hour,
                'minute'    => $minute,
                'is_summer' => $is_summer,
            ]); // 更新档案里的相关
            // 更新档案的缓存 暂时为删除当前档案缓存
            //Cache::forget('recode_' . $rid);
            Cache::forget('recode_lists_' . $uid);
            DB::table('app_recode_info')->where(['rid' => $rid])->update(['last_time' => time()]); // 更新档案最后时间

            DB::table('app_recode_astro')->where(['rid' => $rid])->update($astro_data); // 更新档案行星数据
        } catch (\Exception $e) {
            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        try
        {
//            获取生时校正对应的消息id
            $reids = (new MessageCenter())->select('id')->where('reid', $reid)->first();
            if ($reids || !empty($reids)) {
                //            获取已读的消息id
                $msg = (new UserMsg())->where('uid', $uid)->get(['mid']);
                if ($msg || !empty($msg)) {
                    foreach ($msg as $k => $v) {
                        $mids[] = $v['mid'];
                    }
                    if (!in_array($reids['id'], $mids)) {
                         (new UserMsg())->insertGetId(['mid' => $reids['id'], 'uid' => $uid]);
                    }
                } else {
                      (new UserMsg())->insertGetId(['mid' => $reids['id'], 'uid' => $uid]);
                }

            }
        } catch (\Exception $e) {
            return show(config('code.error'), $e->getMessage(), [], 500);
        }

        $astro_data['rid']       = $rid;
        $astro_data['year']      = $year;
        $astro_data['month']     = $month;
        $astro_data['day']       = $day;
        $astro_data['hour']      = $hour;
        $astro_data['minute']    = $minute;
        $astro_data['is_summer'] = $is_summer;

        return show(config('code.success'), '采纳成功', $astro_data);
    }
    /**
     * 参数规则
     * @name 字段名称
     * @type 类型
     * @require 是否必须
     * @default 默认值
     * @desc 说明
     * @range 范围
     * @return array
     */
    public static function getRules()
    {
        $rules = [
            'index'  => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位'],
                'ucid'         => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位'],
                'page'         => ['name' => 'page', 'type' => 'int', 'require' => 'false', 'default' => '1', 'desc' => '页码', 'range' => '默认为第一页'],
            ],
            'read'   => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位'],
                'ucid'         => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位'],
                'reid'         => ['name' => 'reid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正记录id', 'range' => ''],
            ],
            'save'   => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位'],
                'ucid'         => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位'],
                'rid'          => ['name' => 'rid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '档案id', 'range' => '仅限自己的档案'],
                'start_time'   => ['name' => 'start_time', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正开始时间', 'range' => '秒为单位的时间戳'],
                'end_time'     => ['name' => 'end_time', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正结束时间', 'range' => '秒为单位的时间戳'],
                'events'       => ['name' => 'events', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '校正事件/json', 'range' => '[{"time":1528684429,"type":1,"desc":""}]'],
            ],
            'update' => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位'],
                'ucid'         => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位'],
                'rid'          => ['name' => 'rid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '档案id', 'range' => '仅限自己的档案'],
                'reid'         => ['name' => 'reid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正记录id', 'range' => ''],
                'start_time'   => ['name' => 'start_time', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正开始时间', 'range' => '秒为单位的时间戳'],
                'end_time'     => ['name' => 'end_time', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正结束时间', 'range' => '秒为单位的时间戳'],
                'events'       => ['name' => 'events', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '校正事件/json', 'range' => '[{"time":1528684429,"type":1,"desc":""}]'],
            ],
            'delete' => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位'],
                'ucid'         => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位'],
                'rid'          => ['name' => 'rid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '档案id', 'range' => '仅限自己的档案'],
                'reid'         => ['name' => 'reid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '校正记录id', 'range' => ''],
            ],
            'use'    => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位'],
                'ucid'         => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位'],
                'id'           => ['name' => 'id', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '采纳的结果id', 'range' => ''],
                'reid'         => ['name' => 'reid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '生时校正id', 'range' => ''],
            ],
            'start'  => [
                'access_token' => ['name' => 'access_token', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '接口访问凭证', 'range' => '32位'],
                'ucid'         => ['name' => 'ucid', 'type' => 'string', 'require' => 'true', 'default' => '无', 'desc' => '用户ucid', 'range' => '32位'],
                'reid'         => ['name' => 'reid', 'type' => 'int', 'require' => 'true', 'default' => '无', 'desc' => '生时校正id', 'range' => ''],
            ],
        ];
        return $rules;
    }
}
